<template>
  <main class="heart-card-page">
    <div class="address" @click="goMap(stationData)">
      <i class="iconfont icon-address_icon"></i>
      {{ stationData.address }}
      <b class="goto"><i class="iconfont icon-daohang"></i>导航</b>
    </div>
    <div class="shop-bg">
      <img v-imgUrl="stationData.shop_image" alt="" class="shop_img">
      <a :href="`tel:${stationData.tel}`" class="tel">
        <i class="iconfont icon-dianhua"></i>
      </a>
      <p class="name">{{ stationData.title }}</p>
      <p>营业时间：{{ stationData.business_start_time + ' - ' + stationData.business_end_time }}  </p>
    </div>
    <section class="gas-warp">
      <div>
        <p class="title">柴油实时油价</p>
        <ul class="gas-price">
          <li>
            <p>优惠价</p>
            <span class="rmb">{{ stationData.now_price }}</span>
          </li>
          <li>
            <p>优惠</p>
            <span> {{ stationData.discount }}元/升 </span>
          </li>
          <li>
            <p>油站价</p>
            <span class="rmb">{{ stationData.original_price }}</span>
          </li>
          <li>
            <p>国标价</p>
            <span class="rmb">{{ stationData.nation_price }}</span>
          </li>
        </ul>
      </div>
      <!-- <van-divider /> -->
      <div>
        <p class="title">油站所售油品</p>
        <div class="gas-type">
          <span 
            class="disabled" 
            v-for="item in gas_type" 
            :key="item"
            :class="{active: item == '0#'}">
            {{ item == '0#' ? '柴油' : '汽油' }}{{item}}
          </span>
        </div>
      </div>
      <van-divider />
      <div>
        <p class="title">输入金额</p>
        <div class="input-box">
          <van-field 
            class="gas-input"
            v-model="order_amount" 
            type="number" 
            input-align="center"
            placeholder="在这里输入加油金额"/>
        </div>
        <van-button 
          class="default-btn"
          type="primary" 
          @click="submitOrder"
          block >
          确定
        </van-button>
      </div>
      <van-divider />
      <div class="tip-box" v-if="webinfo.onekeygas_tip">
        <p class="title">注意事项：</p>
        <p class="tip-p">{{webinfo.onekeygas_tip}}</p>
      </div>
    </section>
  </main>
</template>

<script>
import { Toast } from 'vant';
import {mapGetters, mapActions} from 'vuex'
import stationList from 'data/list';
import baseURL from 'api/baseUrlConfig'

export default {
  name: 'heart-card',
  data() {
    return {
      default_shop: require('assets/images/shop.jpg'),
      order_amount: '',
      gas_type: ''
    }
  },
  computed: {
    ...mapGetters([
      'user',
      'stationData',
      'currentPosition',
      'webinfo'
    ])
  },
  created() {
    this.$emit('showTabMenu', false);
    this.gas_type = this.stationData.sell_type.split(';')
  },
  methods: {
    ...mapActions([
      'setHeartCard'
    ]),
    // 导航
    goMap(item) {
      window.location.href = `https://apis.map.qq.com/tools/routeplan/eword=${item.title}&epointx=${item.longitude}&epointy=${item.atitude}?referer=myapp&key=${baseURL.mapKey}`
      // this.$router.push({name: 'StationMap'})
    },
    submitOrder () {
      if (this.gas_type.indexOf('0#') < 0) {
        Toast('该油站暂不能购买柴油!')
        return
      }
      if (!this.order_amount) {
        Toast('金额不能为空')
        return
      }
      if (this.order_amount > 5000) {
        Toast('单笔金额不能超过5000元')
        return
      }
      let params = {
        gas_Type: '柴油0#',
        order_amount: (Number(this.order_amount) * 100).toFixed(0),
        phone: this.user.phone,
        station_id: this.stationData.code_id,
      }
      this.setHeartCard(params)
      this.$router.push({name: 'Order'})
    }
  }
}
</script>

<style lang="less" scoped>
@color: #8BC34A;
@bg: #f5ffe9;

main{
  padding: 0;
}
.address{
  line-height: 40px;
  padding: 0 80px 0 10px;
  box-sizing: border-box;
  align-items: center;
  font-size: 14px;
  background: #f3f3f3;
  height: .8rem;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  word-break: break-all;
  i{
    font-size: 14px;
    color: #2196F3;
    margin-right: 4px;
  }
  .goto{
    position: absolute;
    right: 10px;
  }
}
.shop-bg{
  position: relative;
  height: 160px;
  width: 100%;
  text-align: center;
  padding: 20px 0;
  overflow: hidden;
  background: rgba(0,0,0,.3);
  color: #fff;
  .bg{
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    object-fit: cover;
    mix-blend-mode: multiply;
  }
  .name{
    font-size: 16px;
    font-weight: bold;
  }
  .shop_img{
    width: 120px;
    height: 120px;
    object-fit: cover;
  }
  .tel{
    position: absolute;
    right: 20px;
    bottom: 20px;
    color: #fff;
  }
}
.gas-warp{
  padding: 20px;
}
.header{
  text-align: center;
  .page-title{
    text-align: center;
    font-weight: bold;
    font-size: 16px;
    line-height: 40px;
    padding: 10px 0;
  }
  .logo{
    width: 80px
  }
}
.heart-card-page{
  font-size: 14px;
  .title{
    font-weight: bold;
    font-size: 14px;
    line-height: 40px;
  }
}
.gas-type{
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  span{
    height: 40px;
    line-height: 40px;
    background: #eee;
    text-align: center;
    border-radius: 4px;
    &.disabled{
      color: #a0a0a0;
      cursor: no-drop;
    }
    &.active{
      background: @bg;
      border: 1px solid @color;
      color: @color;
      cursor: unset;
    }
  }
}
.gas-price{
  display: flex;
  justify-content: space-around;
  color: @color;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  background:@bg;
  padding: 8px;
}
.input-box{
  height: 56px;
  width: 100%;
  background: @bg;
  border: 1px solid @color;
  border-radius: 5px;
  margin-bottom: 20px;
  .gas-input{
    background: transparent;
    font-size: 18px;
    font-weight: bold;
    padding: 15px 16px;
    /deep/ input{
      line-height: 28px;
      &::-webkit-input-placeholder{
        font-size: 16px;
        font-weight: 400;
      }
    }
  }
}

</style>
